<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<html>
<head>
<html:base ref="site" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK 
rel=stylesheet type=text/css href="style/register.css">
<link href="style/main.css" rel="stylesheet" type="text/css" />
<script src="js/prototype.lite.js" type="text/javascript"></script>
<script src="js/moo.fx.js" type="text/javascript"></script>
<script src="js/moo.fx.pack.js" type="text/javascript"></script>
<style type="text/css">
.input{display:block;
 margin-left:-180px;
 line-height:15px;
  background: url(images/bt_bg.gif); 
  border: solid 1px #b6b6b6; 
  width:110px; 
  float:center; 
  text-decoration:none; 
  color:#000;
}.input2{display:block;
margin-top:-22px;
 line-height:15px;
  background: url(images/bt_bg.gif); 
  border: solid 1px #b6b6b6; 
  width:110px; 
  float:center; 
  margin-left:110px; 
  text-decoration:none; 
  color:#000;
}
body {
	margin-top: 0px;
}
.STYLE1 {
	font-size: 24px;
	font-weight: bold;
}
</style>
<script language="javascript">
	var req;
	
	function init() {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	//根据院系ID查询DropChangeAJAXAction，获得该院系的专业列表
	function changeDropOfMajor() {
		init();
		
		var url = "dropChangeAJAX.do?method=dropChangeOfMajor&deptId=" + escape(document.forms[0].deptId.options[document.forms[0].deptId.selectedIndex].value);
		
		req.open("get", url, true);
		req.onreadystatechange = callback;
		req.send(null);
	}

	//根据专业ID查询DropChangeAJAXAction，获得该专业的所有班级列表
	function dropChangeOfClazz() {
		init();
		
		var url = "dropChangeAJAX.do?method=dropChangeOfClazz&majorId=" + escape(document.forms[0].majorId.options[document.forms[0].majorId.selectedIndex].value);
		
		req.open("get", url, true);
		req.onreadystatechange = callback;
		req.send(null);
	}
	
	function callback() {
		if (4 == req.readyState) {
			if (200 == req.status) {
				eval(req.responseText);
			}
		}
	}
	
</script>

<script language="javascript">
	function checkForm() {
		var stuId = document.getElementById("stuId").value;
		var nickname = document.getElementById("nickname").value;
		var IDCard = document.getElementById("IDCard").value;
		var sex = document.getElementById("sex").value;
		
		var deptId = document.getElementById("deptId").value;
		var majorId = document.getElementById("majorId").value;
		var clazzId = document.getElementById("clazzId").value;
		
		if (stuId == null || stuId == "") {
			alert("请输入学号！");
			return false;
		}

		if (nickname == null || nickname == "") {
			alert("请输入姓名！");
			return false;
		}

		if (IDCard == null || IDCard == "") {
			alert("请输入身份证号码！");
			return false;
		} else {
			return isIdCardNo(IDCard);
		}

		if (sex == null || sex == "") {
			alert("请选择性别！");
			return false;
		}
		
		if (deptId == 0) {
			alert("请选择所属院系！");
			return false;
		}
		
		if (deptId == 0) {
			alert("请选择所属院系！");
			return false;
		}

		if (majorId == 0) {
			alert("请选择所属专业！");
			return false;
		}

		if (clazzId == 0) {
			alert("请选择所属班级！");
			return false;
		}
		
		return true;
	}

	function isIdCardNo(num) {  
	    num = num.toUpperCase();
	    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。  
	    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
	    	alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');
	        return false;
	    }
		//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
		//下面分别分析出生日期和校验位
		var len, re;
		len = num.length;
		if (len == 15) {
		re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
		var arrSplit = num.match(re);
	
		//检查生日日期是否正确
		var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
		var bGoodDay;
		bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
		if (!bGoodDay)
		{
		          alert('输入的身份证号里出生日期不对！');  
		           return false;
		}
		else
		{
		//将15位身份证转成18位
		//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
		          var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
		           var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
		           var nTemp = 0, i;  
		            num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
		           for(i = 0; i < 17; i ++)
		          {
		                nTemp += num.substr(i, 1) * arrInt[i];
		           }
		           num += arrCh[nTemp % 11];  
		            return num;  
		}  
		}
		if (len == 18)
		{
		re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
		var arrSplit = num.match(re);
	
		//检查生日日期是否正确
		var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
		var bGoodDay;
		bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
		if (!bGoodDay)
		{
		alert(dtmBirth.getYear());
		alert(arrSplit[2]);
		alert('输入的身份证号里出生日期不对！');
		return false;
		}
		else
		{
		//检验18位身份证的校验码是否正确。
		//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
		var valnum;
		var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
		var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
		var nTemp = 0, i;
		for(i = 0; i < 17; i ++)
		{
		nTemp += num.substr(i, 1) * arrInt[i];
		}
		valnum = arrCh[nTemp % 11];
		if (valnum != num.substr(17, 1))
		{
		alert('18位身份证的校验码不正确！应该为：' + valnum);
		return false;
		}
		return num;
		}
		}
		return false;
	}   
</script>
<SCRIPT type=text/javascript 
src="js/register.js"></SCRIPT>

<SCRIPT type=text/javascript 
src="js/GlobalProvinces_main.js"></SCRIPT>
<title>湖北职业技术学院质量评价系统 用户注册</title>

</head>
<body>
<html:form action="register.do?method=regSave" method="post" onsubmit="return checkForm();">
<center>
<DIV id=main_wrap>
<DIV id=top>
<div id="logo"></div>
</DIV>
<DIV id=mid>
  <DIV class=midCnt>
  <br/>
  <span class="STYLE1">学生用户注册    </span>
  <DIV class="midSubCnt line1">
<TABLE  border="0" width="100%">
  <TBODY>
    <TR>
    <TH width="28">
      学号：</TH>
    <TD width="292"> <html:text property="stuId" />
    <font color="#FF0000">如：20090620101！</font></td>
    </TR>
    <TR>
      <td colspan="2"><font color="red">${stuIdRequired } ${stuIdError }${stuIdExist}</font>  </td>
      </TR>
  <TR>
    <TH>姓 名：</TH>
    <TD> <html:text property="nickname" /><font color="red">${nicknameRequired }</font></TD>
  </TR>
  <TR>
    <TH>
      性 别：</TH>
    <TD><html:radio property="sex" value="男" />男
		<html:radio property="sex" value="女" />女 <font color="red">${sexRequired }</font></TD>
  </TR>
  <TR>
    <TH>身份证号码：</TH>
    <TD><html:text property="IDCard" /></TD>
  </TR>
  <TR>
    <td colspan="2" ><div align="left"><font color="red">${IDCardRequired } ${IDCardError } ${IDCardExist }</font></div></td>
    </TR>
  <TR>
    <TH>所属院系：</TH>
    <TD><html:select property="deptId" onchange="changeDropOfMajor()" style="width:130px">
      <html:option value="0">请选择</html:option>
      <html:optionsCollection name="deptList" label="deptName" value="id" />
    </html:select>
      <font color="red">${deptIdRequired }</font></TD>
  </TR>
  <TR>
    <TH>所属专业：</TH>
    <TD><html:select property="majorId" onchange="dropChangeOfClazz()" style="width:130px">
      <html:option value="0">请选择</html:option>
      <c:if test="${!empty majorList}">
        <html:optionsCollection name="majorList" label="majorName" value="id"/>
      </c:if>
    </html:select>
      <font color="red">${majorIdRequired }</font></TD>
  </TR>
  <TR>
    <TH>所属班级： </TH>
    <TD><html:select property="clazzId" style="width:130px">
      <html:option value="0">请选择</html:option>
      <c:if test="${!empty clazzList}">
        <html:optionsCollection name="clazzList" label="clazzId" value="id"/>
      </c:if>
    </html:select>
      <font color="red">${clazzIdRequired }</font></TD>
  </TR>
  </TBODY></TABLE>
 
</DIV>

<DIV id=bottom>
<html:submit value="注册" styleClass="input"/>
<html:reset	value="清空" styleClass="input2"/>
<br/>
<span class="inf_text">版权信息</span> <span
		class="copyright">湖北职业技术学院质量评价系统 Build20100130</span></DIV>
</DIV>
</html:form>
</center>
</body>
</html>
